<?php
class NumberInputWidget extends YWidget {
	public $type = 'normal';//风格
	public $id = null;		//widget_id
	public $name = null;	//表单名称
	public $value = 1;		//默认值
	public $inputOptions = array();	//input属性
	public $min = null;		//最小值
	public $max = null;		//最大值
	public $rule = '^\d+$';	//验证规则
	public $error_callback = null;	//有错时，回调
	public $success_callback = null;//成功时，回调
	public function init(){
		$this->load_resource($this->type);
		if(empty($this->id)){
			$this->id = 'number_input_' . rand(10000, 99999);
		}
		if(!empty($this->name)){
			$this->inputOptions['name'] = $this->name;
		}
		if(!empty($this->min)){
			$this->inputOptions['min'] = $this->min;
		}
		if(!empty($this->max)){
			$this->inputOptions['max'] = $this->max;
		}
		if(!empty($this->rule)){
			$this->inputOptions['rule'] = $this->rule;
		}
		if(!isset($this->inputOptions['id'])){
			$this->inputOptions['id'] = false;
		}
		if(!empty($this->error_callback)){
			$this->inputOptions['error'] = $this->error_callback;
		}
		if(!empty($this->success_callback)){
			$this->inputOptions['success'] = $this->success_callback;
		}
	}
	
	public function run(){
		echo CHtml::tag('div', array('id'=>$this->id, 'class'=>'number_input_widget'), false, false);
		echo CHtml::link('-', 'javascript:void(0)', array('class'=>'des'));
		echo CHtml::textField($this->name, $this->value, $this->inputOptions);
		echo CHtml::link('+', 'javascript:void(0)', array('class'=>'add'));
		echo CHtml::closeTag('div');
	}
}

?>